package lex.mxbeans.ui;

import javax.swing.AbstractListModel;
import javax.swing.JList;

import lex.mxbeans.utils.MXBeanInfo;
import lex.mxbeans.utils.MXBeansUtils;

public class MXBeansList extends JList {
	private AbstractListModel model = null;

	public MXBeansList()
	{
		model = new AbstractListModel(){
			private final MXBeanInfo[] data = MXBeansUtils.getAllMXBeans();

			@Override
			public Object getElementAt( int index )
			{
				return data[index];
			}

			@Override
			public int getSize()
			{
				return data.length;
			}
		};
		this.setModel( model );
	}

	public MXBeanInfo[] getSelectedMXBeans() {
		Object[] values = this.getSelectedValues();
		MXBeanInfo[] beans = new MXBeanInfo[values.length];
		int n = values.length;
		if (0 == n)
			return beans;
		for (int i = 0; i < n; i++)
			beans[i] = (MXBeanInfo) values[i];
		return beans;
	}
}
